package com.linkoog.devtools.intellij.ui.table.column_info.provider.setter;

import com.linkoog.devtools.intellij.ui.table.TableRowData;
import com.linkoog.devtools.intellij.ui.table.column_info.provider.TableCellValueSetterProvider;

import java.lang.reflect.Method;

public class MethodTableCellValueSetterProvider<T extends TableRowData> implements TableCellValueSetterProvider<T> {

    private final String methodName;

    public MethodTableCellValueSetterProvider(String methodName) {
        this.methodName = methodName;
    }

    @Override
    public void setValue(T itemInfo, Object value) {
        try {
            Method method =  itemInfo.getClass().getDeclaredMethod(methodName, value.getClass());
            method.invoke(itemInfo, value);
        } catch (Exception ignored) {
        }
    }
}
